package com.homework.action;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.homework.bean.CourseBean;
import com.homework.bean.UserBean;
import com.homework.service.CourseService;
import com.opensymphony.xwork2.ActionSupport;

public class ClassDeleteAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private CourseService courseService;
	private int courseId;
	private int intPage;
	private int userId;

	public ClassDeleteAction() {
		courseService = new CourseService();
	}

	public int getCourseId() {
		return courseId;
	}

	public void setCourseId(int courseId) {
		this.courseId = courseId;
	}

	public int getIntPage() {
		return intPage;
	}

	public void setIntPage(int intPage) {
		this.intPage = intPage;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	// 删除班级_教师
	public String classDelete_teacher() throws SQLException {
		// courseBean
		CourseBean courseBean = new CourseBean();
		courseBean.setCourseId(String.valueOf(this.getCourseId()));

		courseService.classDelete_teacher(courseBean);
		return "Success";
	}

	// 删除班级_学生
	public String classDelete_student() throws SQLException {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		
		// courseBean
		CourseBean courseBean = new CourseBean();
		courseBean.setCourseId(String.valueOf(this.getCourseId()));
		// userBean
		UserBean userBean = new UserBean();
		if(userId == 0){//踢出学生
			userBean.setUserId(String.valueOf(session.getAttribute("userId")));
		}else{//学生自己退出选课
			userBean.setUserId(String.valueOf(this.getUserId()));
		}
		

		courseService.classDelete_student(courseBean, userBean);
		return "Success";
	}

}
